home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / hplip / ui / scrollprint.py < prev    next >
Text File  |  2008-10-13  |  49KB  |  1,097 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2007 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22. # Local
  23. from base.g import *
  24. from base import utils, magic
  25. from prnt import cups
  26. from ui_utils import load_pixmap
  27.  
  28. # Qt
  29. from qt import *
  30. from scrollview import ScrollView, PixmapLabelButton
  31. from allowabletypesdlg import AllowableTypesDlg
  32. from jobstoragemixin import JobStorageMixin
  33.  
  34. # Std Lib
  35. import os.path
  36. import os
  37. import time
  38.  
  39. class RangeValidator(QValidator):
  40.     def __init__(self, parent=None, name=None):
  41.         QValidator.__init__(self, parent, name)
  42.  
  43.     def validate(self, input, pos):
  44.         for x in unicode(input)[pos-1:]:
  45.             if x not in u'0123456789,- ':
  46.                 return QValidator.Invalid, pos
  47.  
  48.         return QValidator.Acceptable, pos
  49.         
  50.  
  51.  
  52. class FileListViewItem(QListViewItem):
  53.     def __init__(self, parent, index, filename, mime_type_desc, path):
  54.         QListViewItem.__init__(self, parent, str(index+1), filename, mime_type_desc, path)
  55.         self.path = path
  56.         self.index = index
  57.  
  58.  
  59. class ScrollPrintView(ScrollView):
  60.     utils.mixin(JobStorageMixin)
  61.     
  62.     def __init__(self, service, parent=None, form=None, name=None, fl=0):
  63.         ScrollView.__init__(self, service, parent, name, fl)
  64.         
  65.         self.initJobStorage()
  66.         
  67.         self.form = form
  68.         self.file_list = []
  69.         self.pages_button_group = 0
  70.         self.prev_selected_file_index = 0
  71.         
  72.         self.allowable_mime_types = cups.getAllowableMIMETypes()
  73.         self.allowable_mime_types.append("application/x-python")
  74.  
  75.         log.debug(self.allowable_mime_types)
  76.  
  77.         self.MIME_TYPES_DESC = \
  78.         {
  79.             "application/pdf" : (self.__tr("PDF Document"), '.pdf'),
  80.             "application/postscript" : (self.__tr("Postscript Document"), '.ps'),
  81.             "application/vnd.hp-HPGL" : (self.__tr("HP Graphics Language File"), '.hgl, .hpg, .plt, .prn'),
  82.             "application/x-cshell" : (self.__tr("C Shell Script"), '.csh, .sh'),
  83.             "application/x-csource" : (self.__tr("C Source Code"), '.c'),
  84.             "text/cpp": (self.__tr("C++ Source Code"), '.cpp, .cxx'),
  85.             "application/x-perl" : (self.__tr("Perl Script"), '.pl'),
  86.             "application/x-python" : (self.__tr("Python Program"), '.py'),
  87.             "application/x-shell" : (self.__tr("Shell Script"), '.sh'),
  88.             "text/plain" : (self.__tr("Plain Text"), '.txt, .log, etc'),
  89.             "text/html" : (self.__tr("HTML Dcoument"), '.htm, .html'),
  90.             "image/gif" : (self.__tr("GIF Image"), '.gif'),
  91.             "image/png" : (self.__tr("PNG Image"), '.png'),
  92.             "image/jpeg" : (self.__tr("JPEG Image"), '.jpg, .jpeg'),
  93.             "image/tiff" : (self.__tr("TIFF Image"), '.tif, .tiff'),
  94.             "image/x-bitmap" : (self.__tr("Bitmap (BMP) Image"), '.bmp'),
  95.             "image/x-bmp" : (self.__tr("Bitmap (BMP) Image"), '.bmp'),
  96.             "image/x-photocd" : (self.__tr("Photo CD Image"), '.pcd'),
  97.             "image/x-portable-anymap" : (self.__tr("Portable Image (PNM)"), '.pnm'),
  98.             "image/x-portable-bitmap" : (self.__tr("Portable B&W Image (PBM)"), '.pbm'),
  99.             "image/x-portable-graymap" : (self.__tr("Portable Grayscale Image (PGM)"), '.pgm'),
  100.             "image/x-portable-pixmap" : (self.__tr("Portable Color Image (PPM)"), '.ppm'),
  101.             "image/x-sgi-rgb" : (self.__tr("SGI RGB"), '.rgb'),
  102.             "image/x-xbitmap" : (self.__tr("X11 Bitmap (XBM)"), '.xbm'),
  103.             "image/x-xpixmap" : (self.__tr("X11 Pixmap (XPM)"), '.xpm'),
  104.             "image/x-sun-raster" : (self.__tr("Sun Raster Format"), '.ras'),
  105.         }
  106.  
  107.  
  108.     def fillControls(self):
  109.         ScrollView.fillControls(self)
  110.  
  111.         if self.addPrinterFaxList():
  112.             self.addGroupHeading("files_to_print", self.__tr("File(s) to Print"))
  113.             self.addFileList()
  114.             self.addGroupHeading("options", self.__tr("Print Options"))
  115.             self.addCopies()
  116.             self.addPageRange()
  117.             self.addPageSet()
  118.             
  119.             self.job_storage_avail = self.cur_device.mq['job-storage'] == JOB_STORAGE_ENABLE
  120.             
  121.             if self.job_storage_avail:
  122.                 self.addGroupHeading("jobstorage", self.__tr("Job Storage and Secure Printing"))
  123.                 self.addJobStorage()
  124.             
  125.             self.addGroupHeading("space1", "")
  126.     
  127.             self.printButton = self.addActionButton("bottom_nav", self.__tr("Print File(s)"), 
  128.                                     self.printButton_clicked, 'print.png', 'print-disabled.png', 
  129.                                     self.__tr("Close"), self.funcButton_clicked)
  130.     
  131.             self.printButton.setEnabled(False)
  132.             self.maximizeControl()
  133.         
  134.         else:
  135.             QApplication.restoreOverrideCursor()
  136.             self.form.FailureUI("<b>Print is disabled.</b><p>No CUPS print queue found for this device.")
  137.             self.funcButton_clicked()
  138.             
  139.         
  140.     def onUpdate(self, cur_device=None):
  141.         log.debug("ScrollPrintView.onUpdate()")
  142.         self.updateFileList()
  143.         
  144.     def onDeviceChange(self, cur_device=None):
  145.         self.file_list = []
  146.         ScrollView.onDeviceChange(self, cur_device)
  147.  
  148.     def addFileList(self):
  149.         widget = self.getWidget()
  150.         layout37 = QGridLayout(widget,1,1,5,10,"layout37")
  151.  
  152.         self.addFilePushButton = PixmapLabelButton(widget, 
  153.             "list_add.png", "list_add-disabled.png")
  154.  
  155.         layout37.addWidget(self.addFilePushButton,2,0)
  156.  
  157.         self.removeFilePushButton = PixmapLabelButton(widget, 
  158.             "list_remove.png", "list_remove-disabled.png")
  159.  
  160.         layout37.addWidget(self.removeFilePushButton,2,1)
  161.  
  162.         self.moveFileUpPushButton = PixmapLabelButton(widget, "up.png", 
  163.             "up-disabled.png", name='moveFileUpPushButton')
  164.  
  165.         layout37.addWidget(self.moveFileUpPushButton,2,2)
  166.  
  167.         self.moveFileDownPushButton = PixmapLabelButton(widget, "down.png", 
  168.             "down-disabled.png", name='moveFileDownPushButton')
  169.  
  170.         layout37.addWidget(self.moveFileDownPushButton,2,3)
  171.  
  172.         self.showTypesPushButton = PixmapLabelButton(widget, "mimetypes.png", 
  173.             None, name='addFilePushButton')
  174.  
  175.         layout37.addWidget(self.showTypesPushButton,2,5)
  176.         self.fileListView = QListView(widget,"fileListView")
  177.         self.fileListView.addColumn(self.__tr("Order"))
  178.         self.fileListView.addColumn(self.__tr("Name"))
  179.         self.fileListView.addColumn(self.__tr("Type"))
  180.         self.fileListView.addColumn(self.__tr("Path"))
  181.         self.fileListView.setAllColumnsShowFocus(1)
  182.         self.fileListView.setShowSortIndicator(1)
  183.         self.fileListView.setColumnWidth(0, 100)
  184.         self.fileListView.setColumnWidth(1, 150)
  185.         self.fileListView.setColumnWidth(2, 75)
  186.         self.fileListView.setColumnWidth(3, 300)
  187.         self.fileListView.setItemMargin(2)
  188.         self.fileListView.setSorting(-1)
  189.  
  190.         layout37.addMultiCellWidget(self.fileListView,1,1,0,5)
  191.  
  192.         spacer26 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  193.         layout37.addItem(spacer26,2,4)
  194.  
  195.         self.addFilePushButton.setText(self.__tr("Add File..."))
  196.         self.showTypesPushButton.setText(self.__tr("Show Types..."))
  197.         self.removeFilePushButton.setText(self.__tr("Remove File"))
  198.         self.moveFileDownPushButton.setText(self.__tr("Move Down"))
  199.         self.moveFileUpPushButton.setText(self.__tr("Move Up"))
  200.  
  201.         self.removeFilePushButton.setEnabled(False)
  202.         self.moveFileDownPushButton.setEnabled(False)
  203.         self.moveFileUpPushButton.setEnabled(False)
  204.  
  205.         self.connect(self.addFilePushButton, SIGNAL("clicked()"), self.addFile_clicked)
  206.         self.connect(self.removeFilePushButton, SIGNAL("clicked()"), self.removeFile_clicked)
  207.         self.connect(self.showTypesPushButton, SIGNAL("clicked()"), self.showFileTypes_clicked)
  208.         self.connect(self.fileListView,SIGNAL("rightButtonClicked(QListViewItem*,const QPoint&, int)"),self.fileListView_rightButtonClicked)
  209.  
  210.         self.connect(self.moveFileUpPushButton, SIGNAL("clicked()"), self.moveFileUp_clicked)
  211.         self.connect(self.moveFileDownPushButton, SIGNAL("clicked()"), self.moveFileDown_clicked)
  212.         self.connect(self.fileListView, SIGNAL("selectionChanged(QListViewItem*)"), 
  213.             self.fileListView_selectionChanged)
  214.  
  215.         self.addWidget(widget, "file_list", maximize=True)
  216.  
  217.     def fileListView_selectionChanged(self, i):
  218.         try:
  219.             self.prev_selected_file_index = i.index
  220.         except AttributeError:
  221.             pass
  222.         else:
  223.             flv = self.fileListView
  224.             selected_item = flv.selectedItem()
  225.             file_count = flv.childCount()
  226.             last_item = flv.firstChild()
  227.             while last_item.nextSibling():
  228.                 last_item = last_item.nextSibling()
  229.  
  230.             self.moveFileDownPushButton.setEnabled(file_count > 1 and selected_item is not last_item)
  231.             self.moveFileUpPushButton.setEnabled(file_count > 1 and selected_item is not flv.firstChild())        
  232.  
  233.     def fileListView_rightButtonClicked(self, item, pos, col):
  234.         popup = QPopupMenu(self)
  235.         popup.insertItem(QIconSet(load_pixmap('list_add', '16x16')),
  236.             self.__tr("Add File..."), self.addFile_clicked)
  237.  
  238.         if item is not None:
  239.             popup.insertItem(QIconSet(load_pixmap('list_remove', '16x16')),
  240.                 self.__tr("Remove File"), self.removeFile_clicked)
  241.                 
  242.             if self.fileListView.childCount() > 1:
  243.                 last_item = self.fileListView.firstChild()
  244.                 while last_item is not None and last_item.nextSibling():
  245.                     last_item = last_item.nextSibling()
  246.                     
  247.                 if item is not self.fileListView.firstChild():
  248.                     popup.insertItem(QIconSet(load_pixmap('up', '16x16')),
  249.                         self.__tr("Move Up"), self.moveFileUp_clicked)
  250.     
  251.                 if item is not last_item:
  252.                     popup.insertItem(QIconSet(load_pixmap('down', '16x16')),
  253.                         self.__tr("Move Down"), self.moveFileDown_clicked)
  254.  
  255.         popup.insertSeparator(-1)
  256.         popup.insertItem(QIconSet(load_pixmap('mimetypes', '16x16')),
  257.             self.__tr("Show File Types..."), self.showFileTypes_clicked)
  258.  
  259.         popup.popup(pos)
  260.  
  261.     def moveFileUp_clicked(self):
  262.         log.debug("Move file up")
  263.         try:
  264.             item = self.fileListView.selectedItem()
  265.             path, index = item.path, item.index
  266.         except AttributeError:
  267.             return
  268.         else:
  269.             new_pos = index-1
  270.             self.file_list[new_pos], self.file_list[index] = self.file_list[index], self.file_list[new_pos]
  271.             item.index = new_pos
  272.             self.prev_selected_file_index = new_pos
  273.             self.updateFileList()
  274.  
  275.     def moveFileDown_clicked(self):
  276.         log.debug("Move file down")
  277.         try:
  278.             item = self.fileListView.selectedItem()
  279.             path, index = item.path, item.index
  280.         except AttributeError:
  281.             return
  282.         else:
  283.             new_pos = index+1
  284.             self.file_list[index], self.file_list[new_pos] = self.file_list[new_pos], self.file_list[index] 
  285.             item.index = new_pos
  286.             self.prev_selected_file_index = new_pos
  287.             self.updateFileList()
  288.  
  289.     def addFile(self, path):
  290.         path = os.path.realpath(path)
  291.         if os.path.exists(path) and os.access(path, os.R_OK):
  292.             mime_type = magic.mime_type(path)
  293.             mime_type_desc = mime_type
  294.             log.debug(mime_type)
  295.  
  296.             try:
  297.                 mime_type_desc = self.MIME_TYPES_DESC[mime_type][0]
  298.             except KeyError:
  299.                 self.form.FailureUI(self.__tr("<b>You are trying to add a file that cannot be directly printed with this utility.</b><p>To print this file, use the print command in the application that created it."))
  300.             else:
  301.                 log.debug("Adding file %s (%s,%s)" % (path, mime_type, mime_type_desc))
  302.                 self.file_list.append((path, mime_type, mime_type_desc))
  303.         else:
  304.             self.form.FailureUI(self.__tr("<b>Unable to add file '%1' to file list (file not found or insufficient permissions).</b><p>Check the file name and try again.").arg(path))
  305.  
  306.         self.updateFileList()
  307.  
  308.     def updateFileList(self):
  309.         self.fileListView.clear()
  310.         temp = self.file_list[:]
  311.         temp.reverse()
  312.         last_item = None
  313.         selected_item = None
  314.         index = len(temp)-1
  315.  
  316.         for path, mime_type, desc in temp:
  317.             log.debug("path=%s, mime_type=%s, desc=%s, index=%d" % (path, mime_type, desc, index))
  318.             i = FileListViewItem(self.fileListView, index, os.path.basename(path), desc, path)
  319.             
  320.             if self.prev_selected_file_index == index:
  321.                 self.fileListView.setSelected(i, True)
  322.                 self.prev_selected_file_index = index
  323.                 selected_item = i
  324.                 
  325.             index -= 1
  326.  
  327.         last_item = self.fileListView.firstChild()
  328.         while last_item is not None and last_item.nextSibling():
  329.             last_item = last_item.nextSibling()
  330.  
  331.         file_count = self.fileListView.childCount()
  332.         self.moveFileDownPushButton.setEnabled(file_count > 1 and selected_item is not last_item)
  333.         self.moveFileUpPushButton.setEnabled(file_count > 1 and selected_item is not self.fileListView.firstChild())
  334.         self.removeFilePushButton.setEnabled(file_count > 0)
  335.         self.printButton.setEnabled(file_count > 0)
  336.  
  337.     def addFile_clicked(self):
  338.         workingDirectory = user_cfg.last_used.working_dir
  339.  
  340.         if not workingDirectory or not os.path.exists(workingDirectory):
  341.             workingDirectory = os.path.expanduser("~")
  342.  
  343.         log.debug("workingDirectory: %s" % workingDirectory)
  344.  
  345.         dlg = QFileDialog(workingDirectory, QString.null, None, None, True)
  346.  
  347.         dlg.setCaption("openfile")
  348.         dlg.setMode(QFileDialog.ExistingFile)
  349.         dlg.show()
  350.  
  351.         if dlg.exec_loop() == QDialog.Accepted:
  352.                 results = dlg.selectedFile()
  353.                 workingDirectory = unicode(dlg.dir().absPath())
  354.                 log.debug("results: %s" % results)
  355.                 log.debug("workingDirectory: %s" % workingDirectory)
  356.                 user_cfg.last_used.working_dir = workingDirectory
  357.  
  358.                 if results:
  359.                     self.addFile(unicode(results))
  360.  
  361.     def removeFile_clicked(self):
  362.         try:
  363.             path = self.fileListView.selectedItem().path
  364.         except AttributeError:
  365.             return
  366.         else:
  367.             temp = self.file_list[:]
  368.             index = 0
  369.             for p, t, d in temp:
  370.                 if p == path:
  371.                     del self.file_list[index]
  372.                     if index == self.prev_selected_file_index:
  373.                         self.prev_selected_file_index = 0
  374.                     break
  375.                 index += 1
  376.  
  377.             self.updateFileList()
  378.  
  379.     def showFileTypes_clicked(self):
  380.         x = {}
  381.         for a in self.allowable_mime_types:
  382.             x[a] = self.MIME_TYPES_DESC.get(a, ('Unknown', 'n/a'))
  383.  
  384.         log.debug(x)
  385.         dlg = AllowableTypesDlg(x, self)
  386.         dlg.exec_loop()
  387.  
  388.  
  389.     def addCopies(self):
  390.         widget = self.getWidget()
  391.  
  392.         layout12 = QHBoxLayout(widget,5,10,"layout12")
  393.  
  394.         self.textLabel5 = QLabel(widget,"textLabel5")
  395.         layout12.addWidget(self.textLabel5)
  396.         spacer20 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  397.         layout12.addItem(spacer20)
  398.  
  399.         self.copiesSpinBox = QSpinBox(widget,"copiesSpinBox")
  400.         layout12.addWidget(self.copiesSpinBox)
  401.  
  402.         self.copiesDefaultPushButton = QPushButton(widget,"copiesDefaultPushButton")
  403.         layout12.addWidget(self.copiesDefaultPushButton)
  404.  
  405.         self.textLabel5.setText(self.__tr("Number of copies:"))
  406.         self.copiesDefaultPushButton.setText(self.__tr("Default"))
  407.  
  408.         self.copiesSpinBox.setMaxValue(99)
  409.         self.copiesSpinBox.setMinValue(1)
  410.         self.copiesSpinBox.setValue(1)
  411.  
  412.         self.copiesDefaultPushButton.setEnabled(False)
  413.  
  414.         self.connect(self.copiesDefaultPushButton, SIGNAL("clicked()"), self.copiesDefaultPushButton_clicked)
  415.         self.connect(self.copiesSpinBox, SIGNAL("valueChanged(int)"), self.copiesSpinBox_valueChanged)
  416.  
  417.         self.addWidget(widget, "copies")
  418.  
  419.     def copiesDefaultPushButton_clicked(self):
  420.         self.copiesSpinBox.setValue(1)
  421.         self.copiesDefaultPushButton.setEnabled(False)
  422.  
  423.     def copiesSpinBox_valueChanged(self, i):
  424.         self.copiesDefaultPushButton.setEnabled(i != 1)
  425.  
  426.     def addPageRange(self):
  427.         widget = self.getWidget()
  428.  
  429.         layout39 = QGridLayout(widget,1,1,5,10,"layout39")
  430.  
  431.         self.pageRangeEdit = QLineEdit(widget,"self.pageRangeEdit")
  432.         self.pageRangeEdit.setEnabled(0)
  433.         layout39.addWidget(self.pageRangeEdit,0,3)
  434.  
  435.         spacer20_2 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  436.         layout39.addItem(spacer20_2,0,1)
  437.  
  438.         textLabel5_2 = QLabel(widget,"textLabel5_2")
  439.         layout39.addWidget(textLabel5_2,0,0)
  440.  
  441.         self.pagerangeDefaultPushButton = QPushButton(widget,"pagerangeDefaultPushButton")
  442.         layout39.addWidget(self.pagerangeDefaultPushButton,0,4)
  443.  
  444.         self.rangeButtonGroup = QButtonGroup(widget,"self.rangeButtonGroup")
  445.         self.rangeButtonGroup.setLineWidth(0)
  446.         self.rangeButtonGroup.setColumnLayout(0,Qt.Vertical)
  447.         self.rangeButtonGroup.layout().setSpacing(0)
  448.         self.rangeButtonGroup.layout().setMargin(0)
  449.         self.rangeButtonGroupLayout = QGridLayout(self.rangeButtonGroup.layout())
  450.         self.rangeButtonGroupLayout.setAlignment(Qt.AlignTop)
  451.  
  452.         radioButton3_2 = QRadioButton(self.rangeButtonGroup,"radioButton3_2")
  453.         radioButton3_2.setChecked(1)
  454.         self.rangeButtonGroup.insert( radioButton3_2,0)
  455.         self.rangeButtonGroupLayout.addWidget(radioButton3_2,0,0)
  456.  
  457.         radioButton4_2 = QRadioButton(self.rangeButtonGroup,"radioButton4_2")
  458.         self.rangeButtonGroup.insert( radioButton4_2,1)
  459.         self.rangeButtonGroupLayout.addWidget(radioButton4_2,0,1)
  460.  
  461.         layout39.addWidget(self.rangeButtonGroup,0,2)
  462.  
  463.         self.bg = self.pageRangeEdit.paletteBackgroundColor()
  464.         self.invalid_page_range = False
  465.  
  466.         self.pageRangeEdit.setValidator(RangeValidator(self.pageRangeEdit))
  467.  
  468.         textLabel5_2.setText(self.__tr("Page Range:"))
  469.         radioButton3_2.setText(self.__tr("All pages"))
  470.         radioButton4_2.setText(self.__tr("Page range:"))
  471.  
  472.         self.pagerangeDefaultPushButton.setText(self.__tr("Default"))
  473.  
  474.         self.pagerangeDefaultPushButton.setEnabled(False)
  475.  
  476.         self.connect(self.rangeButtonGroup, SIGNAL("clicked(int)"), self.rangeButtonGroup_clicked)
  477.         self.connect(self.pageRangeEdit,SIGNAL("lostFocus()"),self.pageRangeEdit_lostFocus)
  478.         self.connect(self.pageRangeEdit,SIGNAL("textChanged(const QString&)"),self.pageRangeEdit_textChanged)
  479.         self.connect(self.pagerangeDefaultPushButton, SIGNAL("clicked()"), self.pagerangeDefaultPushButton_clicked)
  480.  
  481.         self.addWidget(widget, "range")
  482.  
  483.     def pagerangeDefaultPushButton_clicked(self):
  484.         self.rangeButtonGroup.setButton(0)
  485.         self.pagerangeDefaultPushButton.setEnabled(False)
  486.         self.pageRangeEdit.setEnabled(False)
  487.  
  488.     def rangeButtonGroup_clicked(self, a0):
  489.         self.pages_button_group = a0
  490.         self.pageRangeEdit.setEnabled(a0 == 1)
  491.         self.pagerangeDefaultPushButton.setEnabled(a0 == 1)
  492.  
  493.     def pageRangeEdit_lostFocus(self):
  494.         x = []
  495.         try:
  496.             x = utils.expand_range(unicode(self.pageRangeEdit.text()))
  497.         except ValueError:
  498.             log.error("Invalid page range entered.")
  499.             self.invalid_page_range = True
  500.             self.pageRangeEdit.setPaletteBackgroundColor(QColor(0xff, 0x99, 0x99))
  501.  
  502.         else:
  503.             self.pageRangeEdit.setText(QString(utils.collapse_range(x)))
  504.             self.pageRangeEdit.setPaletteBackgroundColor(self.bg)
  505.             self.invalid_page_range = False
  506.  
  507.     def pageRangeEdit_textChanged(self,a0):
  508.         x = []
  509.         try:
  510.             x = utils.expand_range(str(self.pageRangeEdit.text()))
  511.         except ValueError:
  512.             self.invalid_page_range = True
  513.             self.pageRangeEdit.setPaletteBackgroundColor(QColor(0xff, 0x99, 0x99))
  514.  
  515.         else:
  516.             self.pageRangeEdit.setPaletteBackgroundColor(self.bg)
  517.             self.invalid_page_range = False
  518.  
  519.     def addPageSet(self):
  520.         widget = self.getWidget()
  521.  
  522.         layout34 = QHBoxLayout(widget,5,10,"layout34")
  523.  
  524.         self.textLabel5_4 = QLabel(widget,"textLabel5_4")
  525.         layout34.addWidget(self.textLabel5_4)
  526.         spacer20_4 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  527.         layout34.addItem(spacer20_4)
  528.  
  529.         self.pageSetComboBox = QComboBox(0,widget,"pageSetComboBox")
  530.         layout34.addWidget(self.pageSetComboBox)
  531.  
  532.         self.pagesetDefaultPushButton = QPushButton(widget,"pagesetDefaultPushButton")
  533.         layout34.addWidget(self.pagesetDefaultPushButton)
  534.  
  535.         self.textLabel5_4.setText(self.__tr("Page set:"))
  536.         self.pageSetComboBox.clear()
  537.         self.pageSetComboBox.insertItem(self.__tr("All pages"))
  538.         self.pageSetComboBox.insertItem(self.__tr("Even pages"))
  539.         self.pageSetComboBox.insertItem(self.__tr("Odd pages"))
  540.         self.pagesetDefaultPushButton.setText(self.__tr("Default"))
  541.  
  542.         self.pagesetDefaultPushButton.setEnabled(False)
  543.  
  544.         self.connect(self.pageSetComboBox, SIGNAL("activated(int)"), self.pageSetComboBox_activated)
  545.         self.connect(self.pagesetDefaultPushButton, SIGNAL("clicked()"), self.pagesetDefaultPushButton_clicked)
  546.  
  547.         self.addWidget(widget, "set")
  548.  
  549.     def pagesetDefaultPushButton_clicked(self):
  550.         self.pagesetDefaultPushButton.setEnabled(False)
  551.         self.pageSetComboBox.setCurrentItem(0)
  552.  
  553.     def pageSetComboBox_activated(self, i):
  554.         self.pagesetDefaultPushButton.setEnabled(i != 0)
  555.         
  556. ##    # 
  557. ##    # JOB STORAGE
  558. ##    #
  559. ##    
  560. ##    def addJobStorage(self):
  561. ##        self.addJobStorageMode()
  562. ##        self.addJobStoragePIN()
  563. ##        self.addJobStorageUsername()
  564. ##        self.addJobStorageID()
  565. ##        self.addJobStorageIDExists()
  566. ##        self.jobStorageDisable()
  567. ##        
  568. ##        
  569. ##    def addJobStorageMode(self):
  570. ##        widget = self.getWidget()
  571. ##
  572. ##        layout34 = QHBoxLayout(widget,5,10,"layout34")
  573. ##
  574. ##        self.jobStorageModeLabel = QLabel(widget,"jobStorageModeLabel")
  575. ##        layout34.addWidget(self.jobStorageModeLabel)
  576. ##        spacer20_4 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  577. ##        layout34.addItem(spacer20_4)
  578. ##
  579. ##        self.jobStorageModeComboBox = QComboBox(0,widget,"jobStorageModeComboBox")
  580. ##        layout34.addWidget(self.jobStorageModeComboBox)
  581. ##
  582. ##        self.jobStorageModeDefaultPushButton = QPushButton(widget,"pagesetDefaultPushButton")
  583. ##        layout34.addWidget(self.jobStorageModeDefaultPushButton)
  584. ##
  585. ##        self.jobStorageModeLabel.setText(self.__tr("Job Storage Mode:"))
  586. ##        self.jobStorageModeComboBox.clear()
  587. ##        self.jobStorageModeComboBox.insertItem(self.__tr("Off"))
  588. ##        self.jobStorageModeComboBox.insertItem(self.__tr("Proof and Hold"))
  589. ##        self.jobStorageModeComboBox.insertItem(self.__tr("Personal/Private Job"))
  590. ##        self.jobStorageModeComboBox.insertItem(self.__tr("Quick Copy"))
  591. ##        self.jobStorageModeComboBox.insertItem(self.__tr("Stored Job"))
  592. ##        
  593. ##        self.jobStorageModeDefaultPushButton.setText(self.__tr("Default"))
  594. ##        self.jobStorageModeDefaultPushButton.setEnabled(False)
  595. ##
  596. ##        self.connect(self.jobStorageModeComboBox, SIGNAL("activated(int)"), self.jobStorageModeComboBox_activated)
  597. ##        self.connect(self.jobStorageModeDefaultPushButton, SIGNAL("clicked()"), self.jobStorageModeDefaultPushButton_clicked)
  598. ##
  599. ##        self.addWidget(widget, "job_storage_mode")
  600. ##        
  601. ##    def jobStorageModeComboBox_activated(self, a):
  602. ##        self.job_storage_mode = a
  603. ##        
  604. ##        if a == 0: # Off
  605. ##            self.jobStorageDisable()
  606. ##        
  607. ##        elif a == 1: # Proof and Hold
  608. ##            self.jobStorageModeDefaultPushButton.setEnabled(True)
  609. ##            self.jobStorageUserJobEnable(True)
  610. ##            self.jobStoragePINEnable(False)
  611. ##
  612. ##        elif a == 2: # Private Job
  613. ##            self.jobStorageModeDefaultPushButton.setEnabled(True)
  614. ##            self.jobStoragePINEnable(True)
  615. ##            self.jobStorageUserJobEnable(True)
  616. ##        
  617. ##        elif a == 3: # Quick Copy
  618. ##            self.jobStorageModeDefaultPushButton.setEnabled(True)
  619. ##            self.jobStoragePINEnable(False)
  620. ##            self.jobStorageUserJobEnable(True)
  621. ##        
  622. ##        elif a == 4: # Stored Job
  623. ##            self.jobStorageModeDefaultPushButton.setEnabled(True)
  624. ##            self.jobStoragePINEnable(True) # ???
  625. ##            self.jobStorageUserJobEnable(True)
  626. ##        
  627. ##    def jobStorageModeDefaultPushButton_clicked(self):
  628. ##        self.jobStorageModeComboBox.setCurrentItem(0)
  629. ##        self.job_storage_mode = 0
  630. ##    
  631. ##    def jobStorageDisable(self): # Turn all Off
  632. ##        self.jobStorageModeDefaultPushButton.setEnabled(False)
  633. ##        self.jobStoragePINEnable(False)
  634. ##        self.jobStorageUserJobEnable(False)
  635. ##        
  636. ##    def jobStoragePINEnable(self, e=True): # PIN On/Off
  637. ##        t = e and self.jobStoragePINButtonGroup.selectedId() == 1
  638. ##        self.jobStoragePINButtonGroup.setEnabled(e)
  639. ##        self.jobStoragePINEdit.setEnabled(t)
  640. ##        self.jobStoragePINDefaultPushButton.setEnabled(t)
  641. ##        
  642. ##    def jobStorageUserJobEnable(self, e=True): # Username/Job ID/Job ID Exists On/Off
  643. ##        t = e and self.jobStorageUsernameButtonGroup.selectedId() == 1
  644. ##        self.jobStorageUsernameButtonGroup.setEnabled(e)
  645. ##        self.jobStorageUsernameDefaultPushButton.setEnabled(t)
  646. ##        self.jobStorageUsernameEdit.setEnabled(t)
  647. ##            
  648. ##        t = e and self.jobStorageIDButtonGroup.selectedId() == 1
  649. ##        self.jobStorageIDButtonGroup.setEnabled(e)
  650. ##        self.jobStorageIDDefaultPushButton.setEnabled(t)
  651. ##        self.jobStorageIDEdit.setEnabled(t)
  652. ##        
  653. ##        t = e and self.jobStorageIDExistsComboBox.currentItem() == 1
  654. ##        self.jobStorageIDExistsComboBox.setEnabled(e)
  655. ##        self.jobStorageIDExistsDefaultPushButton.setEnabled(t)
  656. ##        
  657. ##    
  658. ##        
  659. ##    # PIN
  660. ##    
  661. ##        
  662. ##    def addJobStoragePIN(self):
  663. ##        widget = self.getWidget()
  664. ##
  665. ##        layout39 = QGridLayout(widget,1,1,5,10,"layout39")
  666. ##
  667. ##        self.jobStoragePINEdit = QLineEdit(widget,"self.jobStoragePINEdit")
  668. ##        self.jobStoragePINEdit.setMaxLength(4)
  669. ##        self.jobStoragePINEdit.setText(self.job_storage_pin)
  670. ##        layout39.addWidget(self.jobStoragePINEdit,0,3)
  671. ##
  672. ##        spacer20_2 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  673. ##        layout39.addItem(spacer20_2,0,1)
  674. ##
  675. ##        textLabel5_2 = QLabel(widget,"textLabel5_2")
  676. ##        layout39.addWidget(textLabel5_2,0,0)
  677. ##
  678. ##        self.jobStoragePINDefaultPushButton = QPushButton(widget,"jobStoragePINDefaultPushButton")
  679. ##        layout39.addWidget(self.jobStoragePINDefaultPushButton,0,4)
  680. ##
  681. ##        self.jobStoragePINButtonGroup = QButtonGroup(widget,"self.jobStoragePINButtonGroup")
  682. ##        self.jobStoragePINButtonGroup.setLineWidth(0)
  683. ##        self.jobStoragePINButtonGroup.setColumnLayout(0,Qt.Vertical)
  684. ##        self.jobStoragePINButtonGroup.layout().setSpacing(0)
  685. ##        self.jobStoragePINButtonGroup.layout().setMargin(0)
  686. ##        self.jobStoragePINButtonGroupLayout = QGridLayout(self.jobStoragePINButtonGroup.layout())
  687. ##        self.jobStoragePINButtonGroupLayout.setAlignment(Qt.AlignTop)
  688. ##
  689. ##        radioButton3_2 = QRadioButton(self.jobStoragePINButtonGroup,"radioButton3_2")
  690. ##        radioButton3_2.setChecked(1)
  691. ##        self.jobStoragePINButtonGroup.insert( radioButton3_2,0)
  692. ##        self.jobStoragePINButtonGroupLayout.addWidget(radioButton3_2,0,0)
  693. ##
  694. ##        radioButton4_2 = QRadioButton(self.jobStoragePINButtonGroup,"radioButton4_2")
  695. ##        self.jobStoragePINButtonGroup.insert( radioButton4_2,1)
  696. ##        self.jobStoragePINButtonGroupLayout.addWidget(radioButton4_2,0,1)
  697. ##
  698. ##        layout39.addWidget(self.jobStoragePINButtonGroup,0,2)
  699. ##
  700. ##        self.bg = self.jobStoragePINEdit.paletteBackgroundColor()
  701. ##        self.invalid_page_range = False
  702. ##
  703. ##        self.jobStoragePINEdit.setValidator(PINValidator(self.jobStoragePINEdit))
  704. ##
  705. ##        textLabel5_2.setText(self.__tr("Make Job Private (use PIN to print):"))
  706. ##        radioButton3_2.setText(self.__tr("Public/Off"))
  707. ##        radioButton4_2.setText(self.__tr("Private/Use PIN to Print:"))
  708. ##
  709. ##        self.jobStoragePINDefaultPushButton.setText(self.__tr("Default"))
  710. ##
  711. ##        self.connect(self.jobStoragePINButtonGroup, SIGNAL("clicked(int)"), self.jobStoragePINButtonGroup_clicked)
  712. ##        self.connect(self.jobStoragePINEdit,SIGNAL("lostFocus()"),self.jobStoragePINEdit_lostFocus)
  713. ##        self.connect(self.jobStoragePINEdit,SIGNAL("textChanged(const QString&)"),self.jobStoragePINEdit_textChanged)
  714. ##        self.connect(self.jobStoragePINDefaultPushButton, SIGNAL("clicked()"), self.jobStoragePINDefaultPushButton_clicked)
  715. ##
  716. ##        self.addWidget(widget, "job_storage_pin")
  717. ##        
  718. ##    def jobStoragePINButtonGroup_clicked(self, a):
  719. ##        if a == 0: # Public/Off
  720. ##            self.jobStoragePINDefaultPushButton.setEnabled(False)
  721. ##            self.jobStoragePINEdit.setEnabled(False)
  722. ##            self.job_storage_use_pin = False
  723. ##            self.job_storage_pin = u"0000"
  724. ##            
  725. ##        else: # On/Private/Use PIN
  726. ##            self.jobStoragePINDefaultPushButton.setEnabled(True)
  727. ##            self.jobStoragePINEdit.setEnabled(True)
  728. ##            self.job_storage_use_pin = True
  729. ##            self.job_storage_pin = unicode(self.jobStoragePINEdit.text())
  730. ##        
  731. ##    def jobStoragePINEdit_lostFocus(self):
  732. ##        pafss
  733. ##        
  734. ##    def jobStoragePINEdit_textChanged(self, a):
  735. ##        self.job_storage_pin = unicode(a)
  736. ##        
  737. ##    def jobStoragePINDefaultPushButton_clicked(self):
  738. ##        self.jobStoragePINButtonGroup.setButton(0)
  739. ##        self.jobStoragePINDefaultPushButton.setEnabled(False)
  740. ##        self.jobStoragePINEdit.setEnabled(False)
  741. ##        self.job_storage_use_pin = False
  742. ##
  743. ##    # Username    
  744. ##
  745. ##    def addJobStorageUsername(self):
  746. ##        widget = self.getWidget()
  747. ##
  748. ##        layout39 = QGridLayout(widget,1,1,5,10,"layout39")
  749. ##
  750. ##        self.jobStorageUsernameEdit = QLineEdit(widget,"self.jobStorageUsernameEdit")
  751. ##        self.jobStorageUsernameEdit.setMaxLength(16)
  752. ##        self.jobStorageUsernameEdit.setText(self.job_storage_username)
  753. ##        layout39.addWidget(self.jobStorageUsernameEdit,0,3)
  754. ##        
  755. ##        spacer20_2 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  756. ##        layout39.addItem(spacer20_2,0,1)
  757. ##
  758. ##        textLabel5_2 = QLabel(widget,"textLabel5_2")
  759. ##        layout39.addWidget(textLabel5_2,0,0)
  760. ##
  761. ##        self.jobStorageUsernameDefaultPushButton = QPushButton(widget,"jobStorageUsernameDefaultPushButton")
  762. ##        layout39.addWidget(self.jobStorageUsernameDefaultPushButton,0,4)
  763. ##
  764. ##        self.jobStorageUsernameButtonGroup = QButtonGroup(widget,"self.jobStorageUsernameButtonGroup")
  765. ##        self.jobStorageUsernameButtonGroup.setLineWidth(0)
  766. ##        self.jobStorageUsernameButtonGroup.setColumnLayout(0,Qt.Vertical)
  767. ##        self.jobStorageUsernameButtonGroup.layout().setSpacing(0)
  768. ##        self.jobStorageUsernameButtonGroup.layout().setMargin(0)
  769. ##        self.jobStorageUsernameButtonGroupLayout = QGridLayout(self.jobStorageUsernameButtonGroup.layout())
  770. ##        self.jobStorageUsernameButtonGroupLayout.setAlignment(Qt.AlignTop)
  771. ##
  772. ##        radioButton3_2 = QRadioButton(self.jobStorageUsernameButtonGroup,"radioButton3_2")
  773. ##        radioButton3_2.setChecked(1)
  774. ##        self.jobStorageUsernameButtonGroup.insert( radioButton3_2,0)
  775. ##        self.jobStorageUsernameButtonGroupLayout.addWidget(radioButton3_2,0,0)
  776. ##
  777. ##        radioButton4_2 = QRadioButton(self.jobStorageUsernameButtonGroup,"radioButton4_2")
  778. ##        self.jobStorageUsernameButtonGroup.insert( radioButton4_2,1)
  779. ##        self.jobStorageUsernameButtonGroupLayout.addWidget(radioButton4_2,0,1)
  780. ##
  781. ##        layout39.addWidget(self.jobStorageUsernameButtonGroup,0,2)
  782. ##
  783. ##        self.bg = self.jobStorageUsernameEdit.paletteBackgroundColor()
  784. ##        self.invalid_page_range = False
  785. ##
  786. ##        self.jobStorageUsernameEdit.setValidator(TextValidator(self.jobStorageUsernameEdit))
  787. ##
  788. ##        textLabel5_2.setText(self.__tr("User name (for job identification):"))
  789. ##        radioButton3_2.setText(self.__tr("Automatic"))
  790. ##        radioButton4_2.setText(self.__tr("Custom:"))
  791. ##
  792. ##        self.jobStorageUsernameDefaultPushButton.setText(self.__tr("Default"))
  793. ##
  794. ##        self.connect(self.jobStorageUsernameButtonGroup, SIGNAL("clicked(int)"), self.jobStorageUsernameButtonGroup_clicked)
  795. ##        self.connect(self.jobStorageUsernameEdit,SIGNAL("lostFocus()"),self.jobStorageUsernameEdit_lostFocus)
  796. ##        self.connect(self.jobStorageUsernameEdit,SIGNAL("textChanged(const QString&)"),self.jobStorageUsernameEdit_textChanged)
  797. ##        self.connect(self.jobStorageUsernameDefaultPushButton, SIGNAL("clicked()"), self.jobStorageUsernameDefaultPushButton_clicked)
  798. ##
  799. ##        self.addWidget(widget, "job_storage_username")
  800. ##        
  801. ##    def jobStorageUsernameButtonGroup_clicked(self, a):
  802. ##        if a == 0: # Automatic
  803. ##            self.jobStorageUsernameDefaultPushButton.setEnabled(False)
  804. ##            self.jobStorageUsernameEdit.setEnabled(False)
  805. ##            self.job_storage_auto_username = True
  806. ##            self.job_storage_username = unicode(prop.username[:16])
  807. ##        
  808. ##        else: # Custom
  809. ##            self.jobStorageUsernameDefaultPushButton.setEnabled(True)
  810. ##            self.jobStorageUsernameEdit.setEnabled(True)
  811. ##            self.job_storage_auto_username = False
  812. ##            self.job_storage_username = unicode(self.jobStorageUsernameEdit.text())
  813. ##            
  814. ##    def jobStorageUsernameEdit_lostFocus(saddJobStorageIDelf):
  815. ##        pass
  816. ##        
  817. ##    def jobStorageUsernameEdit_textChanged(self, a):
  818. ##        self.job_storage_username = unicode(a)
  819. ##        
  820. ##    def jobStorageUsernameDefaultPushButton_clicked(self):
  821. ##        self.jobStorageUsernameButtonGroup.setButton(0)
  822. ##        self.jobStorageUsernameDefaultPushButton.setEnabled(False)
  823. ##        self.jobStorageUsernameEdit.setEnabled(False)
  824. ##        self.job_storage_auto_username = True
  825. ##        self.job_storage_username = unicode(prop.username[:16])
  826. ##
  827. ##    # Job ID    
  828. ##
  829. ##    def addJobStorageID(self):
  830. ##        widget = self.getWidget()
  831. ##
  832. ##        layout39 = QGridLayout(widget,1,1,5,10,"layout39")
  833. ##
  834. ##        self.jobStorageIDEdit = QLineEdit(widget,"self.jobStorageIDEdit")
  835. ##        self.jobStorageIDEdit.setMaxLength(16)
  836. ##        self.jobStorageIDEdit.setText(self.job_storage_jobname)
  837. ##        layout39.addWidget(self.jobStorageIDEdit,0,3)
  838. ##
  839. ##        spacer20_2 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  840. ##        layout39.addItem(spacer20_2,0,1)
  841. ##
  842. ##        textLabel5_2 = QLabel(widget,"textLabel5_2")
  843. ##        layout39.addWidget(textLabel5_2,0,0)
  844. ##
  845. ##        self.jobStorageIDDefaultPushButton = QPushButton(widget,"jobStorageIDDefaultPushButton")
  846. ##        layout39.addWidget(self.jobStorageIDDefaultPushButton,0,4)
  847. ##
  848. ##        self.jobStorageIDButtonGroup = QButtonGroup(widget,"self.jobStorageIDButtonGroup")
  849. ##        self.jobStorageIDButtonGroup.setLineWidth(0)
  850. ##        self.jobStorageIDButtonGroup.setColumnLayout(0,Qt.Vertical)
  851. ##        self.jobStorageIDButtonGroup.layout().setSpacing(0)
  852. ##        self.jobStorageIDButtonGroup.layout().setMargin(0)
  853. ##        self.jobStorageIDButtonGroupLayout = QGridLayout(self.jobStorageIDButtonGroup.layout())
  854. ##        self.jobStorageIDButtonGroupLayout.setAlignment(Qt.AlignTop)
  855. ##
  856. ##        radioButton3_2 = QRadioButton(self.jobStorageIDButtonGroup,"radioButton3_2")
  857. ##        radioButton3_2.setChecked(1)
  858. ##        self.jobStorageIDButtonGroup.insert( radioButton3_2,0)
  859. ##        self.jobStorageIDButtonGroupLayout.addWidget(radioButton3_2,0,0)
  860. ##
  861. ##        radioButton4_2 = QRadioButton(self.jobStorageIDButtonGroup,"radioButton4_2")
  862. ##        self.jobStorageIDButtonGroup.insert( radioButton4_2,1)
  863. ##        self.jobStorageIDButtonGroupLayout.addWidget(radioButton4_2,0,1)
  864. ##
  865. ##        layout39.addWidget(self.jobStorageIDButtonGroup,0,2)
  866. ##
  867. ##        self.bg = self.jobStorageIDEdit.paletteBackgroundColor()
  868. ##        self.invalid_page_range = False
  869. ##
  870. ##        self.jobStorageIDEdit.setValidator(TextValidator(self.jobStorageIDEdit))
  871. ##
  872. ##        textLabel5_2.setText(self.__tr("Job name (for job identification):"))
  873. ##        radioButton3_2.setText(self.__tr("Automatic"))
  874. ##        radioButton4_2.setText(self.__tr("Custom:"))
  875. ##
  876. ##        self.jobStorageIDDefaultPushButton.setText(self.__tr("Default"))
  877. ##
  878. ##        self.connect(self.jobStorageIDButtonGroup, SIGNAL("clicked(int)"), self.jobStorageIDButtonGroup_clicked)
  879. ##        self.connect(self.jobStorageIDEdit,SIGNAL("lostFocus()"),self.jobStorageIDEdit_lostFocus)
  880. ##        self.connect(self.jobStorageIDEdit,SIGNAL("textChanged(const QString&)"),self.jobStorageIDEdit_textChanged)
  881. ##        self.connect(self.jobStorageIDDefaultPushButton, SIGNAL("clicked()"), self.jobStorageIDDefaultPushButton_clicked)
  882. ##
  883. ##        self.addWidget(widget, "job_storage_ID")
  884. ##        
  885. ##    def jobStorageIDButtonGroup_clicked(self, a):
  886. ##        if a == 0: # Automatic
  887. ##            self.jobStorageIDDefaultPushButton.setEnabled(False)
  888. ##            self.jobStorageIDEdit.setEnabled(False)
  889. ##            self.job_storage_auto_jobname = True
  890. ##            self.job_storage_jobname = unicode(time.strftime("%a, %d %b %Y %H:%M:%S"))
  891. ##            
  892. ##        else: # Custom
  893. ##            self.jobStorageIDDefaultPushButton.setEnabled(True)
  894. ##            self.jobStorageIDEdit.setEnabled(True)
  895. ##            self.job_storage_auto_jobname = False
  896. ##            self.job_storage_jobname = unicode(self.jobStorageIDEdit.text())
  897. ##        
  898. ##    def jobStorageIDEdit_lostFocus(self):
  899. ##        pass
  900. ##        
  901. ##    def jobStorageIDEdit_textChanged(self, a):
  902. ##        self.job_storage_jobname = unicode(a)
  903. ##                
  904. ##    def jobStorageIDDefaultPushButton_clicked(self):
  905. ##        self.jobStorageIDButtonGroup.setButton(0)
  906. ##        self.jobStorageIDDefaultPushButton.setEnabled(False)
  907. ##        self.jobStorageIDEdit.setEnabled(False)
  908. ##        self.job_storage_auto_jobname = True
  909. ##        self.job_storage_jobname = unicode(time.strftime("%a, %d %b %Y %H:%M:%S"))
  910. ##
  911. ##    # Job ID Exists
  912. ##
  913. ##    def addJobStorageIDExists(self):
  914. ##        widget = self.getWidget()
  915. ##
  916. ##        layout34 = QHBoxLayout(widget,5,10,"layout34")
  917. ##
  918. ##        self.jobStorageIDExistsLabel = QLabel(widget,"jobStorageIDExistsLabel")
  919. ##        layout34.addWidget(self.jobStorageIDExistsLabel)
  920. ##        spacer20_4 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  921. ##        layout34.addItem(spacer20_4)
  922. ##
  923. ##        self.jobStorageIDExistsComboBox = QComboBox(0,widget,"jobStorageIDExistsComboBox")
  924. ##        layout34.addWidget(self.jobStorageIDExistsComboBox)
  925. ##
  926. ##        self.jobStorageIDExistsDefaultPushButton = QPushButton(widget,"pagesetDefaultPushButton")
  927. ##        layout34.addWidget(self.jobStorageIDExistsDefaultPushButton)
  928. ##
  929. ##        self.jobStorageIDExistsLabel.setText(self.__tr("If Job Name already exists:"))
  930. ##        self.jobStorageIDExistsComboBox.clear()
  931. ##        self.jobStorageIDExistsComboBox.insertItem(self.__tr("Replace existing job"))
  932. ##        self.jobStorageIDExistsComboBox.insertItem(self.__tr("Use Job Name + (1-99)"))
  933. ##        
  934. ##        self.jobStorageIDExistsDefaultPushButton.setText(self.__tr("Default"))
  935. ##
  936. ##        self.connect(self.jobStorageIDExistsComboBox, SIGNAL("activated(int)"), self.jobStorageIDExistsComboBox_activated)
  937. ##        self.connect(self.jobStorageIDExistsDefaultPushButton, SIGNAL("clicked()"), self.jobStorageIDExistsDefaultPushButton_clicked)
  938. ##
  939. ##        self.addWidget(widget, "job_storage_id_exists")
  940. ##        
  941. ##    def jobStorageIDExistsComboBox_activated(self, a):
  942. ##        self.jobStorageIDExistsDefaultPushButton.setEnabled(a==1)
  943. ##        self.job_storage_job_exist = a
  944. ##        
  945. ##    def jobStorageIDExistsDefaultPushButton_clicked(self):
  946. ##        self.jobStorageIDExistsComboBox.setCurrentItem(0)
  947. ##        self.jobStorageIDExistsDefaultPushButton.setEnabled(False)
  948. ##        self.job_storage_job_exist = 0
  949. ##
  950. ##        
  951. ##    #
  952. ##    #    
  953. ##    #    
  954.  
  955.     def printButton_clicked(self):
  956.         if self.invalid_page_range:
  957.             self.form.FailureUI(self.__tr("<b>Cannot print: Invalid page range: %1</b><p>A valid page range is a list of pages or ranges of pages separated by commas (e.g., 1-2,4,6-7)").arg(self.pageRangeEdit.text()))
  958.             return
  959.  
  960.         try:
  961.             try:
  962.                 self.cur_device.open()
  963.             except Error:
  964.                 self.form.FailureUI(self.__tr("<b>Cannot print: Device is busy or not available.</b><p>Please check device and try again."))
  965.                 return
  966.  
  967.             if 1: # Go ahead and allow - print will be queued in CUPS if not rejecting
  968.                 printers = cups.getPrinters()
  969.                 for p in printers:
  970.                     if p.name == self.cur_printer:
  971.                         break
  972.                 
  973.                 if p.state == cups.IPP_PRINTER_STATE_STOPPED:
  974.                     self.form.FailureUI(self.__tr("<b>Cannot print: Printer is stopped.</b><p>Please START the printer to continue this print. Job will begin printing once printer is started."))
  975.  
  976.                 if not p.accepting:
  977.                     self.form.FailureUI(self.__tr("<b>Cannot print: Printer is not accepting jobs.</b><p>Please set the printer to ACCEPTING JOBS to continue printing."))
  978.                     return
  979.                 
  980.                 copies = int(self.copiesSpinBox.value())
  981.                 all_pages = self.pages_button_group == 0
  982.                 page_range = unicode(self.pageRangeEdit.text())
  983.                 page_set = int(self.pageSetComboBox.currentItem())
  984.  
  985.                 cups.resetOptions()
  986.                 cups.openPPD(self.cur_printer)
  987.                 current_options = dict(cups.getOptions())
  988.                 cups.closePPD()
  989.  
  990.                 nup = int(current_options.get("number-up", 1))
  991.  
  992.                 for p, t, d in self.file_list:
  993.  
  994.                     alt_nup = (nup > 1 and t == 'application/postscript' and utils.which('psnup'))
  995.  
  996.                     if utils.which('lpr'):
  997.                         if alt_nup:
  998.                             cmd = ' '.join(['psnup', '-%d' % nup, ''.join(['"', p, '"']), '| lpr -P', self.cur_printer])
  999.                         else:
  1000.                             cmd = ' '.join(['lpr -P', self.cur_printer])
  1001.  
  1002.                         if copies > 1:
  1003.                             cmd = ' '.join([cmd, '-#%d' % copies])
  1004.  
  1005.                     else:
  1006.                         if alt_nup:
  1007.                             cmd = ' '.join(['psnup', '-%d' % nup, ''.join(['"', p, '"']), '| lp -c -d', self.cur_printer])
  1008.                         else:
  1009.                             cmd = ' '.join(['lp -c -d', self.cur_printer])
  1010.  
  1011.                         if copies > 1:
  1012.                             cmd = ' '.join([cmd, '-n%d' % copies])
  1013.  
  1014.  
  1015.                     if not all_pages and len(page_range) > 0:
  1016.                         cmd = ' '.join([cmd, '-o page-ranges=%s' % page_range])
  1017.  
  1018.                     if page_set > 0:
  1019.                         if page_set == 1:
  1020.                             cmd = ' '.join([cmd, '-o page-set=even'])
  1021.                         else:
  1022.                             cmd = ' '.join([cmd, '-o page-set=odd'])
  1023.  
  1024.                     
  1025.                     # Job Storage
  1026.                     # self.job_storage_mode = (0=Off, 1=P&H, 2=PJ, 3=QC, 4=SJ)
  1027.                     # self.job_storage_pin = u"" (dddd)
  1028.                     # self.job_storage_use_pin = True|False
  1029.                     # self.job_storage_username = u""
  1030.                     # self.job_storage_auto_username = True|False
  1031.                     # self.job_storage_jobname = u""
  1032.                     # self.job_storage_auto_jobname = True|False
  1033.                     # self.job_storage_job_exist = (0=replace, 1=job name+(1-99))
  1034.                     
  1035.                     if self.job_storage_avail: 
  1036.                         if self.job_storage_mode: # On
  1037.                             
  1038.                             if self.job_storage_mode == 1: # Proof and Hold
  1039.                                 cmd = ' '.join([cmd, '-o HOLD=PROOF'])
  1040.                                 
  1041.                             elif self.job_storage_mode == 2: # Private Job
  1042.                                 if self.job_storage_use_pin:
  1043.                                     cmd = ' '.join([cmd, '-o HOLD=ON'])
  1044.                                     cmd = ' '.join([cmd, '-o HOLDTYPE=PRIVATE'])
  1045.                                     cmd = ' '.join([cmd, '-o HOLDKEY=%s' % self.job_storage_pin.encode('ascii')])
  1046.                                 else:
  1047.                                     cmd = ' '.join([cmd, '-o HOLD=PROOF'])
  1048.                                     cmd = ' '.join([cmd, '-o HOLDTYPE=PRIVATE'])
  1049.                                 
  1050.                             elif self.job_storage_mode == 3: # Quick Copy
  1051.                                 cmd = ' '.join([cmd, '-o HOLD=ON'])
  1052.                                 cmd = ' '.join([cmd, '-o HOLDTYPE=PUBLIC'])
  1053.  
  1054.                             elif self.job_storage_mode == 4: # Store Job
  1055.                                 if self.job_storage_use_pin:
  1056.                                     cmd = ' '.join([cmd, '-o HOLD=STORE'])
  1057.                                     cmd = ' '.join([cmd, '-o HOLDTYPE=PRIVATE'])
  1058.                                     cmd = ' '.join([cmd, '-o HOLDKEY=%s' % self.job_storage_pin.encode('ascii')])
  1059.                                 else:
  1060.                                     cmd = ' '.join([cmd, '-o HOLD=STORE'])
  1061.                                 
  1062.                             cmd = ' '.join([cmd, '-o USERNAME=%s' % self.job_storage_username.encode('ascii')\
  1063.                                 .replace(" ", "_")])
  1064.                             
  1065.                             cmd = ' '.join([cmd, '-o JOBNAME=%s' % self.job_storage_jobname.encode('ascii')\
  1066.                                 .replace(" ", "_")])
  1067.                             
  1068.                             if self.job_storage_job_exist == 1:
  1069.                                 cmd = ' '.join([cmd, '-o DUPLICATEJOB=APPEND']) 
  1070.                             else:
  1071.                                 cmd = ' '.join([cmd, '-o DUPLICATEJOB=REPLACE'])
  1072.                         
  1073.                         else: # Off
  1074.                             cmd = ' '.join([cmd, '-o HOLD=OFF'])
  1075.                     
  1076.                     
  1077.                     if not alt_nup:
  1078.                         cmd = ''.join([cmd, ' "', p, '"'])
  1079.  
  1080.                     log.debug("Printing: %s" % cmd)
  1081.  
  1082.                     code = os.system(cmd)
  1083.                     if code != 0:
  1084.                         log.error("Print command failed.")
  1085.                         self.form.FailureUI(self.__tr("Print command failed with error code %1").arg(code))
  1086.  
  1087.                 self.form.close()
  1088.  
  1089.         finally:
  1090.             self.cur_device.close()
  1091.  
  1092.     def funcButton_clicked(self):
  1093.         self.form.close()
  1094.  
  1095.     def __tr(self,s,c = None):
  1096.         return qApp.translate("ScrollPrintView",s,c)
  1097.